<?php
namespace app\shuiyin\controller;
use app\shuiyin\model\Wechat;
use think\Controller;
// use think\Loader;
// Loader::import('Qiniu', EXTEND_PATH);
// require EXTEND_PATH.'qiniuyun/autoload.php';
// use Qiniu\Auth;
// use Qiniu\Storage\UploadManager;
class Index extends Controller{
	public function __construct(){
		parent::__construct();
		$this->wechat = new Wechat();
	}
	public function index(){
		$result = $this->wechat->getSignature();
		$this->assign('appId',$this->wechat->appid);
		$this->assign('timestamp',$result['timestamp']);
		$this->assign('nonceStr',$result['noncestr']);
		$this->assign('signature',$result['signature']);
		$this->assign('_title',"我为2018全球博研同学慈善年会打call！");
		$this->assign('_desc',"快来制作你的专属代言海报，筑梦助学。");
		$this->assign('_imgUrl',"http://wxshuiyin.byeducation.com/public/static/shuiyin/images/logo.jpg");
		$this->assign('_shareLink',"http://wxshuiyin.byeducation.com/public/index.php/shuiyin/index/index");

		// $accessKey = 'ZaWu8rwg1xq66o8beXDd5qdwgH1smF0e4a5RfJKA';
		// $secretKey = '_e_BBbLA3kE13x9fwcMdVGszfFAMxi5ve2T7R1Vq';
		// $auth = new Auth($accessKey, $secretKey);
		// $bucket = 'hintrinh-image';
		// // 生成上传Token
		// $token = $auth->uploadToken($bucket);
		// // dump($token);
		// // 构建 UploadManager 对象
		// // $uploadMgr = new UploadManager();
		// $this->assign('token',$token);
		
		return $this->fetch('Index/test');
	}
	// public function getQiniuToken(){
	// 	$accessKey = 'ZaWu8rwg1xq66o8beXDd5qdwgH1smF0e4a5RfJKA';
	// 	$secretKey = '_e_BBbLA3kE13x9fwcMdVGszfFAMxi5ve2T7R1Vq';
	// 	$auth = new Auth($accessKey, $secretKey);
	// 	$bucket = 'hintrinh-image';
	// 	// 生成上传Token
	// 	$token = $auth->uploadToken($bucket);
	// 	return json_encode(array('uptoken',$token));
	// }
	public function getAccessToken(){	
		$result = $this->wechat->getSignature();
		return dump($result) ;
	}
	public function checkAuth(){
		$echoStr = isset($_GET['echostr']) ? $_GET['echostr'] : '';
		if ($this->wechat->checkSignature() && $echoStr) {
			return $echoStr;
		}
	}

}